Practical No. 1: Write a program to demonstrate the use of AWT components.

  

I. Practical Significance:

Text Field, Text Area, Button, Checkbox, Radio Buttons(Check Box Group) are the AWT components. Used to design the GUI in java. A component is object having representation that can be displayed on the screen to interact with the user.

 

II. Relevant Program Outcomes (POs)

 Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the computer group related problems.

Discipline knowledge: Apply Computer Programming knowledge to solve the computer group related problems.

Experiments and practice: Plan to perform experiments and practices to use the results to solve the computer group related problems.

Engineering tools: Apply relevant Computer programming / technologies and  tools with an understanding of the limitations.

Individual and Team work: Function effectively as a leader and team member in diverse/multidisciplinary teams.

Communication: Communicate effectively in oral and written form.


III. Competency and Practical skills

To develop standalone applications

The practical is expected to develop the following skills:

1.     Able to design form using required AWT components

2.     Able to understand the different Components available in AWT


IV. Relevant Course Outcome(s)

Develop programs using GUI Framework AWT.

 

V. Practical Outcome (PrOs)

Write a program to demonstrate the use of AWT components.

 

VI. Relevant Affective domain related Outcome(s)

1.     Follow precautionary measures.

2.     Follow naming conventions.

3.     Follow ethical practices.

 

VII. Minimum Theoretical Background

AWT is a java programming language class library. Components are visible objects  that can interact with the user. Containers (Frame, Panel, Applet) are used to hold components using in a specific layout.

 Using applet window, design following AWT components using add() method of components class. Following are some AWT components

 1.     Label: Creates a label that displays a string.

2.     TextField Creates and accepts a single-line text from user.

3.     TextArea Creates and accepts multiple line text from user.

4.     Button creates a push button.

5.     Checkbox Creates a check box which is used to select multiple options.

6.     CheckboxGroup creates a group of checkbox to act as radio button.

 

To Create TextArea:

TextArea ta=new TextArea(String str,int nooflines)

 To create RadioButton(CheckBoxGroup): 

CheckBox cb1,  cb2; CheckBoxGroup cbg;

Cb1=new CheckBox(“Male”,cbg,true); 

Cb2=new CheckBox(“Female”,cbg,false);

 

VIII.      Resources required

 

Sr.

No.

Name of Resource

Broad Specification

Quantity

Remarks

(If any)

1

Computer System

Computer (i3-i5 preferable RAM > 2GB

 

As per Batch Size

 

 

For All Experiments

2

Operating System

Windows/Linux

3

Development Software

JDK 1.5 Onwards

 

Program Code: Teacher must assign a separate program statement to group of  3-4 students.

1.     Design an applet/application to demonstrate the use of Radio Button  and  Checkbox.

Ans:

import java.awt.*;

public class PR1a{

    public static void main(String[] args) {

        Frame f = new Frame();

        Label l1 = new Label("Welcome to java");

        l1.setBounds(100, 100, 120, 100);

        f.add(l1);

        f.setSize(300, 300);

        f.setLayout(null);

        f.setVisible(true);

    }

}

 

2.     Design an applet/application to create form using Text Field,  Text Area,  Button and Label.

Ans:

import java.awt.*;

public class PR1b{

    public static void main(String[] args) {

        Frame f = new Frame();

        Checkbox c1 = new Checkbox("English");

        Checkbox c2 = new Checkbox("Hindi");

        Checkbox c3 = new Checkbox("Marathi");

        Checkbox c4 = new Checkbox("Sanskrit");

        c1.setBounds(100, 100, 100, 50);

        c2.setBounds(100, 150, 100, 50);

        c3.setBounds(100, 200, 100, 50);

        c4.setBounds(100, 250, 100, 50);

        f.add(c1);

        f.add(c2);

        f.add(c3);

        f.add(c4);

        f.setSize(400, 400);

        f.setLayout(null);

        f.setVisible(true);

    }

}


Practical Related Questions

Note: Below given are few sample questions for reference. Teacher must  design  more such questions so as to ensure the achievement of identified CO.

1.     State the difference between CheckBox and RadioButton

Ans:  

Radio button

Checkbox

1]It is used when only one option to be selected out of several available options.

1]Checkbox allows one or many options to be selected.

2]It is a single control unit.

2]It is a multiple control unit.



2.     
Write the use of setEnabled() method.

Ans: The setEnalbled() method is ued to enable or disable Components. To enable a component setEnabled method is used as setEnabled(true) and to disable a component setEnabled method is used as setEnabled(false).

3.     Draw the life cycle of an Applet.

Ans:


Exercise:

1.     Develop a program using Label to display message “Welcome to Java”

import java.awt.*;

public class PR1a{

    public static void main(String[] args) {

        Frame f = new Frame();

        Label l1 = new Label("Welcome to java");

        l1.setBounds(100, 100, 120, 100);

        f.add(l1);

        f.setSize(300, 300);

        f.setLayout(null);

        f.setVisible(true);

    }

}


2.     2Develop a program to select multiple languages known to user. (e. g Marathi,  Hindi, English, Sanskrit).

import java.awt.*;

public class PR1b{

    public static void main(String[] args) {

        Frame f = new Frame();

        Checkbox c1 = new Checkbox("English");

        Checkbox c2 = new Checkbox("Hindi");

        Checkbox c3 = new Checkbox("Marathi");

        Checkbox c4 = new Checkbox("Sanskrit");

        c1.setBounds(100, 100, 100, 50);

        c2.setBounds(100, 150, 100, 50);

        c3.setBounds(100, 200, 100, 50);

        c4.setBounds(100, 250, 100, 50);

        f.add(c1);

        f.add(c2);

        f.add(c3);

        f.add(c4);

        f.setSize(400, 400);

        f.setLayout(null);

        f.setVisible(true);

    }

}

3.     Write a program to create three Buttons with Caption OK, RESET and CANCEL.

import java.awt.*;

public class PR1c{
public static void main(String[] args) {
Frame f = new Frame();
Button B1 = new Button("Ok");
Button B2 = new Button("Reset");
Button B3 = new Button("Cancel");
B1.setBounds(100, 100, 100, 50);
B2.setBounds(100, 170, 100, 50);
B3.setBounds(100, 240, 100, 50);
f.add(B1);
f.add(B2);
f.add(B3);
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
}
}




Comments